<?php

namespace app\course\event\subscribes\video\admin;

use app\admin\logic\system\Log;
use app\course\event\listeners\video\admin\{SectionAdd, SectionDelete};
use think\Event;

class Video
{
    public function subscribe(Event $event)
    {
        $admin = '管理员【' . request()->user->user_name . '/' . request()->user->id . '】';

        /** 新建 */
        $event->listen('VideoCreated', function ($video) use ($admin) {

            Log::write($admin . '创建了' . $video->getAttr('course_log_type') . '《' . $video->title . '》', 'course_video', 'create');
        });

        /** 更新 */
        $event->listen('VideoUpdated', function ($video) use ($admin) {
            Log::write($admin . '修改了' . $video->getAttr('course_log_type') . '《' . $video->title . '》的信息', 'course_video', 'update');
        });

        /** 删除 */
        $event->listen('VideoDeleted', function ($video) use ($admin) {
            Log::write($admin . '删除了' . $video->getAttr('course_log_type') . '《' . $video->title . '》', 'course_video', 'delete');
        });

        /** 新建 */
        $event->listen('SectionAdd', SectionAdd::class);

        /** 删除 */
        $event->listen('SectionDelete', SectionDelete::class);

    }
}
